from celery import shared_task
from ronglianyunapi import send_sms as sms
# 记录日志：
import logging
logger = logging.getLogger("django")
from django.conf import settings
from sendEmail import send_vcode

# @shared_task(name="send_sms")
# def send_sms(tid, mobile, datas):
#     """异步发送短信"""
#     try:
#         return sms(tid, mobile, datas)
#     except Exception as e:
#         logger.error(f"手机号：{mobile}，发送短信失败错误: {e}")
#
#
# @shared_task(name="send_sms1")
# def send_sms1():
#     print("send_sms1执行了！！！")

@shared_task(name="send_sms")
def send_sms(to_addr, smtp_server=settings.SMTP_SERVER,
             from_addr=settings.FROM_EMAIL, password=settings.EMAIL_PASSWORD,
             send_me=""):
    """异步发送短信"""
    try:
        return send_vcode(to_addr, smtp_server, from_addr, password, f"您好，欢迎提交你的注册账号。每60秒可以注册一次，验证码只有5分钟有效，请立即注册，  {send_me}   ")
    except Exception as e:
        logger.error(f"邮箱：{smtp_server}，发送短信失败错误: {e}")


@shared_task(name="send_sms1")
def send_sms1():
    print("send_sms1执行了！！！")